public void simple() { //START SNIPPET: simple Patient pat = new Patient(); pat.getText().setStatus(NarrativeStatusEnum.GENERATED); pat.getText().setDiv("<div>This is the narrative text<br/>this is line 2</div>"); //END SNIPPET: simple }
public void namesEasy() { // START SNIPPET: namesEasy Patient patient = new Patient(); patient.addName().addFamily("Smith").addGiven("Rob").addGiven("Bruce"); // END SNIPPET: namesEasy }
@Search private List<IBaseResource> searchForPatients() { // Create an organization Organization org = new Organization(); org.setId("Organization/65546"); org.setName("Test Organization"); // Create a patient Patient patient = new Patient(); patient.setId("Patient/1333"); patient.addIdentifier().setSystem("urn:mrns").setValue("253345"); patient.getManagingOrganization().setResource(org); // Here we return only the patient object, which has links to other resources List<IBaseResource> retVal = new ArrayList<IBaseResource>(); retVal.add(patient); return retVal; } // END SNIPPET: addIncludes
public void namesHard() { // START SNIPPET: namesHard Patient patient = new Patient(); HumanNameDt name = patient.addName(); StringDt family = name.addFamily(); family.setValue("Smith"); StringDt firstName = name.addGiven(); firstName.setValue("Rob"); StringDt secondName = name.addGiven(); secondName.setValue("Bruce"); // END SNIPPET: namesHard }
@Read public Patient read(@IdParam IdDt theId) { if (databaseIsDown) { OperationOutcome oo = new OperationOutcome(); oo.addIssue().setSeverity(IssueSeverityEnum.FATAL).setDetails("Database is down"); throw new InternalErrorException("Database is down", oo); } Patient patient = new Patient(); // populate this return patient; } //END SNIPPET: returnOO
/** * The "@Search" annotation indicates that this method supports the * search operation. You may have many different method annotated with * this annotation, to support many different search criteria. This * example searches by family name. * * @param theIdentifier * This operation takes one parameter which is the search criteria. It is * annotated with the "@Required" annotation. This annotation takes one argument, * a string containing the name of the search criteria. The datatype here * is StringDt, but there are other possible parameter types depending on the * specific search criteria. * @return * This method returns a list of Patients. This list may contain multiple * matching resources, or it may also be empty. */ @Search() public List<Patient> getPatient(@RequiredParam(name = Patient.SP_FAMILY) StringDt theFamilyName) { Patient patient = new Patient(); patient.addIdentifier(); patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL); patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); patient.getIdentifier().get(0).setValue("00001"); patient.addName(); patient.getName().get(0).addFamily("Test"); patient.getName().get(0).addGiven("PatientOne"); patient.setGender(AdministrativeGenderEnum.MALE); return Collections.singletonList(patient); }
@Search public List<Patient> getAllPatients() { ArrayList<Patient> retVal = new ArrayList<Patient>(); // Create a patient to return Patient patient = new Patient(); patient.setId("Patient/123"); patient.addName().addFamily("Smith").addGiven("John"); // Create a tag list and add it to the resource TagList tags = new TagList(); ResourceMetadataKeyEnum.TAG_LIST.put(patient, tags); // Add some tags to the list tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag1.html", "Some tag"); tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag2.html", "Another tag"); return retVal; } // END SNIPPET: serverMethod
/** * The "@Search" annotation indicates that this method supports the * search operation. You may have many different method annotated with * this annotation, to support many different search criteria. This * example searches by family name. * * @param theFamilyName * This operation takes one parameter which is the search criteria. It is * annotated with the "@Required" annotation. This annotation takes one argument, * a string containing the name of the search criteria. The datatype here * is StringParam, but there are other possible parameter types depending on the * specific search criteria. * @return * This method returns a list of Patients. This list may contain multiple * matching resources, or it may also be empty. */ @Search() public List<Patient> getPatient(@RequiredParam(name = Patient.SP_FAMILY) StringParam theFamilyName) { Patient patient = new Patient(); patient.addIdentifier(); patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL); patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); patient.getIdentifier().get(0).setValue("00001"); patient.addName(); patient.getName().get(0).addFamily(theFamilyName.getValue()); patient.getName().get(0).addGiven("PatientOne"); patient.setGender(AdministrativeGenderEnum.MALE); return Collections.singletonList(patient); }
/** * The "@Read" annotation indicates that this method supports the * read operation. It takes one argument, the Resource type being returned. * * @param theId * The read operation takes one parameter, which must be of type * IdDt and must be annotated with the "@Read.IdParam" annotation. * @return * Returns a resource matching this identifier, or null if none exists. */ @Read() public Patient getResourceById(@IdParam IdDt theId) { Patient patient = new Patient(); patient.addIdentifier(); patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); patient.getIdentifier().get(0).setValue("00002"); patient.addName().addFamily("Test"); patient.getName().get(0).addGiven("PatientOne"); patient.setGender(AdministrativeGenderEnum.FEMALE); return patient; }
/** * The "@Read" annotation indicates that this method supports the * read operation. Read operations should return a single resource * instance. * * @param theId * The read operation takes one parameter, which must be of type * IdDt and must be annotated with the "@Read.IdParam" annotation. * @return * Returns a resource matching this identifier, or null if none exists. */ @Read() public Patient getResourceById(@IdParam IdDt theId) { Patient patient = new Patient(); patient.addIdentifier(); patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); patient.getIdentifier().get(0).setValue("00002"); patient.addName().addFamily("Test"); patient.getName().get(0).addGiven("PatientOne"); patient.setGender(AdministrativeGenderEnum.FEMALE); return patient; }
public void fluent() throws DataFormatException { FhirContext ctx = new FhirContext(Patient.class, Observation.class); String encoded; //START SNIPPET: encodeMsgFluent Patient patient = new Patient(); patient.addIdentifier().setSystem("http://example.com/fictitious-mrns").setValue("MRN001"); patient.addName().setUse(NameUseEnum.OFFICIAL).addFamily("Tester").addGiven("John").addGiven("Q"); encoded = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(encoded); //END SNIPPET: encodeMsgFluent }
public static void manualContained() { // START SNIPPET: manualContained // Create an organization, and give it a local ID Organization org = new Organization(); org.setId("#localOrganization"); org.getNameElement().setValue("Contained Test Organization"); // Create a patient Patient patient = new Patient(); patient.setId("Patient/1333"); patient.addIdentifier().setSystem("urn:mrns").setValue("253345"); // Set the reference, and manually add the contained resource patient.getManagingOrganization().setReference("#localOrganization"); patient.getContained().getContainedResources().add(org); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(encoded); // END SNIPPET: manualContained }
@SuppressWarnings("unused") public static void codes() { // START SNIPPET: codes Patient patient = new Patient(); // You can set this code using a String if you want. Note that // for "closed" valuesets (such as the one used for Patient.gender) // you must use one of the strings defined by the FHIR specification. // You must not define your own. patient.getGenderElement().setValue("male"); // HAPI also provides Java enumerated types which make it easier to // deal with coded values. This code achieves the exact same result // as the code above. patient.setGender(AdministrativeGenderEnum.MALE); // You can also retrieve coded values the same way String genderString = patient.getGenderElement().getValueAsString(); AdministrativeGenderEnum genderEnum = patient.getGenderElement().getValueAsEnum(); // The following is a shortcut to create patient.setMaritalStatus(MaritalStatusCodesEnum.M); // END SNIPPET: codes }
public void foo() { //START SNIPPET: subExtension Patient patient = new Patient(); ExtensionDt parent = new ExtensionDt(false, "http://example.com#parent"); patient.addUndeclaredExtension(parent); ExtensionDt child1 = new ExtensionDt(false, "http://example.com#childOne", new StringDt("value1")); parent.addUndeclaredExtension(child1); ExtensionDt child2 = new ExtensionDt(false, "http://example.com#childTwo", new StringDt("value1")); parent.addUndeclaredExtension(child2); //END SNIPPET: subExtension }
public void foo() { //START SNIPPET: subExtension Patient patient = new Patient(); // Add an extension (initially with no contents) to the resource ExtensionDt parent = new ExtensionDt(false, "http://example.com#parent"); patient.addUndeclaredExtension(parent); // Add two extensions as children to the parent extension ExtensionDt child1 = new ExtensionDt(false, "http://example.com#childOne", new StringDt("value1")); parent.addUndeclaredExtension(child1); ExtensionDt child2 = new ExtensionDt(false, "http://example.com#childTwo", new StringDt("value1")); parent.addUndeclaredExtension(child2); //END SNIPPET: subExtension }
Patient patient = new Patient();
public static void main(String[] args) throws DataFormatException, IOException { //START SNIPPET: example1 Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:foo").setValue("7000135"); patient.addName().addFamily("Smith").addGiven("John").addGiven("Edward"); patient.addAddress().addLine("742 Evergreen Terrace").setCity("Springfield").setState("ZZ"); FhirContext ctx = FhirContext.forDstu2(); // Use the narrative generator ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); // Encode the output, including the narrative String output = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(output); //END SNIPPET: example1 }
@SuppressWarnings("unused") public static void codeableConcepts() { // START SNIPPET: codeableConcepts Patient patient = new Patient(); // Coded types can naturally be set using plain strings CodingDt statusCoding = patient.getMaritalStatus().addCoding(); statusCoding.setSystem("http://hl7.org/fhir/v3/MaritalStatus"); statusCoding.setCode("M"); statusCoding.setDisplay("Married"); // You could add a second coding to the field if needed too. This // can be useful if you want to convey the concept using different // codesystems. CodingDt secondStatus = patient.getMaritalStatus().addCoding(); secondStatus.setCode("H"); secondStatus.setSystem("http://example.com#maritalStatus"); secondStatus.setDisplay("Happily Married"); // CodeableConcept also has a text field meant to convey // a user readable version of the concepts it conveys. patient.getMaritalStatus().setText("Happily Married"); // There are also accessors for retrieving values String firstCode = patient.getMaritalStatus().getCoding().get(0).getCode(); String secondCode = patient.getMaritalStatus().getCoding().get(1).getCode(); // END SNIPPET: codeableConcepts }
@SuppressWarnings("unused") public static void main(String[] args) throws DataFormatException, IOException { Patient patient = new Patient(); patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:fake:mrns").setValue("7000135"); patient.addIdentifier().setUse(IdentifierUseEnum.SECONDARY).setSystem("urn:fake:otherids").setValue("3287486"); patient.addName().addFamily("Smith").addGiven("John").addGiven("Q").addSuffix("Junior"); patient.setGender(AdministrativeGenderEnum.MALE); FhirContext ctx = FhirContext.forDstu2(); String xmlEncoded = ctx.newXmlParser().encodeResourceToString(patient); String jsonEncoded = ctx.newJsonParser().encodeResourceToString(patient); MyClientInterface client = ctx.newRestfulClient(MyClientInterface.class, "http://foo/fhir"); IdentifierDt searchParam = new IdentifierDt("urn:someidentifiers", "7000135"); List<Patient> clients = client.findPatientsByIdentifier(searchParam); }
@SuppressWarnings("unused") public static void codeableConceptEnums() { Patient patient = new Patient();