Last active
December 6, 2016 07:48
-
-
Save ybon3/334ab9e31ca6e62abb008cee5631380d to your computer and use it in GitHub Desktop.
AutoCare Testing Fhir resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dtc.autocare.portal.server.fhir.repository; | |
import java.io.File; | |
import java.io.IOException; | |
import java.nio.charset.StandardCharsets; | |
import org.apache.http.HttpHeaders; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.client.methods.CloseableHttpResponse; | |
import org.apache.http.client.methods.HttpPut; | |
import org.apache.http.entity.ContentType; | |
import org.apache.http.entity.StringEntity; | |
import org.apache.http.impl.client.HttpClientBuilder; | |
import org.json.JSONArray; | |
import org.json.JSONObject; | |
import com.google.common.io.Files; | |
public class CreateFakeData2 { | |
protected static final String MIME_TYPE = "application/json"; | |
protected static final ContentType CONTENT_TYPE = ContentType.create(MIME_TYPE, StandardCharsets.UTF_8); | |
private static final String BASE_URL = "http://localhost:8013/baseDstu2/"; | |
private static final File FOLDER = new File("D:\\fhir server\\data samples"); //自己改路徑 | |
public static void main(String[] args) throws Exception { | |
//資料有因果關係,要注意順序 | |
gen("Patient", "Patient.resource.txt"); | |
gen("Organization", "Organization.resource.txt"); | |
gen("DiagnosticReport", "DiagnosticReport.resource.txt"); | |
gen("ImagingStudy", "ImagingStudy.resource.txt"); | |
} | |
public static void gen(String resource, String fname) throws Exception { | |
JSONArray arr = new JSONArray( | |
Files.toString( | |
new File(FOLDER, fname), | |
StandardCharsets.UTF_8 | |
) | |
); | |
for (int i = 0; i < arr.length(); i++) { | |
JSONObject data = arr.getJSONObject(i); | |
update(data.toString(), resource + "/" + data.get("id")); | |
} | |
} | |
public static boolean update(String jsonData, String resource) { | |
HttpPut putRequest = new HttpPut(BASE_URL + resource); | |
putRequest.addHeader(HttpHeaders.CONTENT_TYPE, MIME_TYPE); | |
StringEntity input = new StringEntity(jsonData, CONTENT_TYPE); | |
putRequest.setEntity(input); | |
HttpClient client = HttpClientBuilder.create().build(); | |
HttpResponse response = null; | |
try { | |
response = client.execute(putRequest); | |
System.out.println(resource + ": " + response.getStatusLine().getStatusCode()); | |
//System.out.println(IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8)); | |
if (response.getStatusLine().getStatusCode() != 200 | |
&& response.getStatusLine().getStatusCode() != 201) { | |
return false; | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return false; | |
} finally { | |
closeResponse(response); | |
} | |
return true; | |
} | |
public static void closeResponse(HttpResponse response) { | |
if (response != null && response instanceof CloseableHttpResponse) { | |
try { | |
((CloseableHttpResponse) response).close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"resourceType":"DiagnosticReport", | |
"id":"REP.849", | |
"text":{ | |
"status":"empty", | |
"div":"<div>No narrative available - Error: Could not parse as expression: \"Untitled Diagnostic Report\" (diagnosticreport:15)</div>" | |
}, | |
"category":{ | |
"text":"CT" | |
}, | |
"subject":{ | |
"reference":"Patient/ID.401", | |
"display":"John" | |
}, | |
"performer":{ | |
"reference":"Organization/datacom.test", | |
"display":"合華醫院" | |
} | |
}, | |
{ | |
"resourceType":"DiagnosticReport", | |
"id":"REP.725", | |
"text":{ | |
"status":"empty", | |
"div":"<div>No narrative available - Error: Could not parse as expression: \"Untitled Diagnostic Report\" (diagnosticreport:15)</div>" | |
}, | |
"category":{ | |
"text":"MRI" | |
}, | |
"subject":{ | |
"reference":"Patient/ID.401", | |
"display":"John" | |
}, | |
"performer":{ | |
"reference":"Organization/732.77860873", | |
"display":"高雄市立岡山醫院(委託秀傳醫療社團法人經營)" | |
} | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"resourceType":"ImagingStudy", | |
"id":"IMG.519", | |
"patient":{ | |
"reference":"Patient/ID.401", | |
"display":"John" | |
}, | |
"identifier":[ | |
{ | |
"assigner":{ | |
"reference":"Organization/266.1004140", | |
"display":"衛生福利部旗山醫院" | |
} | |
} | |
], | |
"series":[ | |
{ | |
"modality":{ | |
"code":"US" | |
}, | |
"started":"2016-11-21T17:08:18.667+08:00", | |
"instance":[ | |
{ | |
"title":"我是 instant Ya" | |
} | |
] | |
} | |
] | |
}, | |
{ | |
"resourceType":"ImagingStudy", | |
"id":"IMG.525", | |
"patient":{ | |
"reference":"Patient/ID.401", | |
"display":"John" | |
}, | |
"identifier":[ | |
{ | |
"assigner":{ | |
"reference":"Organization/266.1004140", | |
"display":"衛生福利部旗山醫院" | |
} | |
} | |
], | |
"series":[ | |
{ | |
"modality":{ | |
"code":"CT" | |
}, | |
"started":"2016-10-21T17:08:18.667+08:00", | |
"instance":[ | |
{ | |
"title":"我是 instance Ya" | |
} | |
] | |
} | |
] | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"resourceType":"Organization", | |
"id":"datacom.test", | |
"name":"合華醫院", | |
"telecom":[ | |
{ | |
"value":"02.22485858" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"725.29122727", | |
"name":"中祥醫院", | |
"telecom":[ | |
{ | |
"value":"725.29122727" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"947.35865650", | |
"name":"秀傳醫院", | |
"telecom":[ | |
{ | |
"value":"947.35865650" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"732.77860873", | |
"name":"高雄市立岡山醫院(委託秀傳醫療社團法人經營)", | |
"telecom":[ | |
{ | |
"value":"732.77860873" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"920.06805109", | |
"name":"杏和醫院", | |
"telecom":[ | |
{ | |
"value":"920.06805109" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"037-46511587", | |
"name":"榮總醫院", | |
"telecom":[ | |
{ | |
"value":"037-46511587" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"123.456789", | |
"name":"榮總醫院", | |
"telecom":[ | |
{ | |
"value":"12345-6789" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"969.23125362", | |
"name":"順安醫院", | |
"telecom":[ | |
{ | |
"value":"969.23125362" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"02.22250891", | |
"name":"榮總醫院", | |
"telecom":[ | |
{ | |
"value":"02.22250891" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"951.08540576", | |
"name":"高雄市立聯合醫院", | |
"telecom":[ | |
{ | |
"value":"951.08540576" | |
} | |
] | |
}, | |
{ | |
"resourceType":"Organization", | |
"id":"266.10041409", | |
"name":"衛生福利部旗山醫院", | |
"telecom":[ | |
{ | |
"value":"266.10041409" | |
} | |
] | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"resourceType":"Patient", | |
"id":"ID.401", | |
"text":{ | |
"status":"generated", | |
"div":"<div xmlns=\"http://www.w3.org/1999/xhtml\">TESTING</div>" | |
}, | |
"name":[ | |
{ | |
"text":"John", | |
"given":["John"] | |
} | |
], | |
"telecom":[ | |
{ | |
"system":"phone", | |
"value":"15896154923" | |
} | |
], | |
"gender":"male", | |
"birthDate":"1976-07-15", | |
"address":[ | |
{ | |
"line":["Taiwan 15896154923\r\r"] | |
} | |
], | |
"contact":[ | |
{ | |
"name":{ | |
"text":"no", | |
"given":["no"] | |
} | |
} | |
] | |
}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment