MyHealth — Adding People
Before Thanksgiving, we created the model that lets us represent people in MyHealth. Now let’s add some people, particularly my family, because that’s what I’m building MyHealth for in the first place.
First, we’ll replace the front Viewlet with one that shows a list of people whose data is being managed. So we open up MainViewletFactory.java and make its determineFactoryChoicesIgnoringType method look like this:
public ViewletFactoryChoice [] determineFactoryChoicesIgnoringType(
MeshObjectsToView toView )
{
JeeMeshObjectsToView realToView = (JeeMeshObjectsToView) toView;
ArrayList<ViewletFactoryChoice> ret = new ArrayList<ViewletFactoryChoice>();
MeshObject subject = toView.getSubject();
if( subject.getMeshBase().getHomeObject() == subject ) {
ret.add( DefaultJspViewlet.choice( realToView, “org.infogrid.myhealth.viewlet.patients.PatientsCollectionViewlet”, ViewletFactoryChoice.PERFECT_MATCH_QUALITY ));
ret.add( AllMeshObjectsViewlet.choice( realToView, ViewletFactoryChoice.GOOD_MATCH_QUALITY ));
ret.add( AllMeshTypesViewlet.choice( realToView, ViewletFactoryChoice.AVERAGE_MATCH_QUALITY ));
}
ret.add( DefaultJspViewlet.choice( realToView, “org.infogrid.jee.viewlet.propertysheet.PropertySheetViewlet”, ViewletFactoryChoice.AVERAGE_MATCH_QUALITY ));
return ArrayHelper.copyIntoNewArray( ret, ViewletFactoryChoice.class );
}
This means that preferably, the app’s front page is now going to be run by a Viewlet called org.infogrid.myhealth.viewlet.patients.PatientsCollectionViewlet. Which we’ll create by creating
- a JSP file called
PatientsCollectionViewlet.jspat locationweb/v/org/infogrid/myhealth/viewlet/patients/. For now, just put in a placeholder HTML content. - a corresponding CSS file at
web/v/org/infogrid/myhealth/viewlet/patients/PatientsCollectionViewlet.css. - A property file that contains the name of the viewlet, at
java/org/infogrid/myhealth/viewlet/patients/PatientsCollectionViewlet.properties.
(You can find their content in SVN).
Finally, we use the InfoGrid JSPO mechanism (”Java Server Pages Overlay”) to quickly add an editable GUI. The essence of that is this code in the JSP:
<u:callJspo page="/o/personcollection/create-patient.jspo" action="${Viewlet.postUrl}" linkTitle="Create a new patient" submitLabel="Create">
<img src="${CONTEXT}/s/images/add.png" alt="[add]” />
</u:callJspo>
This includes a JSP fragment with the overlay dialog, which looks like this:
<h2>Create patient</h2> <input name="shell.patientcollection.access" type="hidden" value="find" /> <input name="shell.patientcollection" type="hidden" value="users" /> <input name="shell.patientcollection.to.patient.perform" type="hidden" value="relateifneeded" /> <input name="shell.patientcollection.to.patient.blessRole" type="hidden" value="org.infogrid.model.MyHealth/PersonCollection_Collects_Person-S" /> <input name="shell.patient.access" type="hidden" value="create" /> <input name="shell.patient.bless" type="hidden" value="org.infogrid.model.MyHealth/Person" /> <table class="form" border="0"> <tbody> <tr> <th class="label">At URL:</th> <td> <input class="identifier" name="shell.patient" size="32" value="users/" /></td> </tr> <tr> <th class="label">First name:</th> <td></td> </tr> <tr> <th class="label">Last name:</th> <td></td> </tr> </tbody></table>
This uses the HTTP Shell to create a new MeshObject of type Person, which is related to the PersonCollection of users we created earlier, using RelationshipType PersonCollection_Collects_Person. Note that the .jspo file type needs to be declared as JSP file type in the app’s web.xml file.
A few additions to CSS and Javascript (again found in SVN), and we recompile and run.
Now we can add users to the app. Check it out!
